package com.yaorange.module.system.controller;

import com.yaorange.module.system.service.SysUserRoleService;
import com.yaorange.pojo.SysUserRole;
import com.yaorange.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/userRole")
@Slf4j
public class SysUserRoleController {
    @Autowired
    SysUserRoleService sysUserRoleService;

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        log.info("查询用户角色列表");
        List<SysUserRole> list = sysUserRoleService.findById(id);
        return Result.success(list);
    }

    @PostMapping("/{userId}")
    public Result addRelation(@PathVariable Long userId,@RequestBody List<Long> roles) {
        log.info("添加用户角色,id:"+userId+"  roles:"+roles);
        sysUserRoleService.addRelation(userId,roles);
        return Result.success();
    }
}
